//
//  ADManage.m
//  BDDynamicGridViewDemo
//
//  Created by kawang on 7/22/12.
//  Copyright (c) 2012 Bluedot. All rights reserved.
//

#import "ADManage.h"
#import "Constants.h"

@implementation ADManage
static ADManage* singlon = nil;

+(id)shareManage
{
    if (singlon == nil) 
    {
        singlon = [[ADManage alloc] init];
    }
    return singlon;
}

-(id)init
{
    if (self = [super init]) 
    {
        reWardWall = [[RewardedWallViewController alloc] init];
        
        adView = [[YouMiView alloc] initWithContentSizeIdentifier:YouMiBannerContentSizeIdentifier320x50 delegate:nil];
        
        ////////////////[必填]///////////////////
        // 设置APP ID 和 APP Secret
        adView.appID = kDefaultAppID_iOS;
        adView.appSecret = kDefaultAppSecret_iOS;
        
        ////////////////[可选]///////////////////
        // 设置您应用的版本信息
        adView.appVersion = @"1.0";
        
        // 设置您应用的推开渠道号
        // adView2.channelID = 1;
        
        // 设置您应用的广告请求模式
        // adView2.testing = NO;
        
        // 可以设置委托
        adView.delegate = self;
        
        // 设置文字广告的属性
        adView.indicateBorder = NO;
        adView.indicateTranslucency = NO;
        adView.indicateRounded = YES;
        
        // adView2.indicateBackgroundColor = [UIColor purpleColor];
        // adView2.textColor = [UIColor whiteColor];
        // adView2.subTextColor = [UIColor yellowColor];
        
        // 添加对应的关键词
        // [adView2 addKeyword:@"女性"];
        // [adView2 addKeyword:@"19岁"];
        
        // 开始请求广告
        [adView start];
        
        // 设置位置
        CGRect frame = adView.frame;
        frame.origin.x = 0;
        frame.origin.y = 370;
        adView.frame = frame;
        
    }
    return self;
}

-(void)pushTheAdWallWith:(UINavigationController*)navigationController
{
    [navigationController pushViewController:reWardWall animated:YES];
}

-(void)showAdWith:(UIView*)delegateView
{
    if (adView.superview != nil) 
    {
        [adView removeFromSuperview];
    }
    [delegateView addSubview:adView];
}

-(void)dismissAd
{
    [adView removeFromSuperview];
}

#pragma mark YouMiView Delegate 

- (void)didReceiveAd:(YouMiView *)adView 
{
    NSLog(@"---*--[iPhone ]请求广告成功--*---");
}

- (void)didFailToReceiveAd:(YouMiView *)adView  error:(NSError *)error 
{
    NSLog(@"---*--[iPhone ]请求广告失败:%@--*---" ,error);    
}

- (void)willPresentScreen:(YouMiView *)adView 
{
    NSLog(@"---*--[iPhone ]将要显示全屏广告--*---");
}

- (void)didPresentScreen:(YouMiView *)adView 
{
    NSLog(@"---*--[iPhone ]显示全屏广告完成--*---");
}

- (void)willDismissScreen:(YouMiView *)adView 
{
    NSLog(@"---*--[iPhone ]将要隐藏全屏广告--*---");
}

- (void)didDismissScreen:(YouMiView *)adView 
{
    NSLog(@"---*--[iPhone ]全屏广告隐藏完成--*---");
}

@end
